<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */

    /*********************************************************
    *            --== InArch ==--
    *
    * INA Admin Core, this in every solution's heart and soul. The main
    * purpose of this file is to cast all the objects neccessary
    * for some part of a solution. It is also the URI parser which
    * figures out what part of the solution the user has requested.
    *
    * It is vital that the init.inc.php file is called at the
    * beginning of this file, as it will grant all the neccessary
    * resources for the application in form of a database layer
    * and a template parser.
    *
    * adminCore.inc.php is a subfile, meaning that it will be called by
    * any solution inside admin part of the application. Thus it
    * is neccessary that the solution provides adminCore.inc.php with
    * two constants: INA_ROOT and ROOT both resembling path to
    * the INA core files and the solution's root respectively.
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 22.04.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/
    error_reporting(E_ALL & ~E_NOTICE);
    
    //get hold of the control framework
    //it casts $db, $smarty and $_CONFIG
    require_once INA_ROOT.'init.inc.php';

    //create Admin Log Writer (global scope)
    $GLOBALS['myLog'] = new logDB($db,'admin',$_CONFIG['print_errors']);
	
    ###### -- Security Check -- ################
    #
    // is there an active admin session?

    if(!isset($_SESSION['admin'])){    // no?
        // @2do -- make sure open admin sessions are tied
        //         to one IP address

        //lets try to establish one!
        $loginProcessor = new loginProcessor($db,$smarty,$myLog);
        $loginProcessor->login();
    }
    #
    ###### -- End Security Check -- ############

    ###### -- Admin Module Registry -- #########
    #
    // first check if there is a subsection call in the CP

    if(isset($_GET['view'])){

        //there was a subsection call, thus try to cast one!
        try{
            //cast the requested controller
            $controller = adminFactory::cast($_GET['view'],$db,$smarty,$myLog);
        //no joy, thus cast a 404
        }catch(exception $e){
            //record error message
            $myLog->recordError($e->getMessage(),$e->getCode(),true);

            //cast a 404 page controller
            $controller = adminFactory::cast('404',$db,$smarty,$myLog);
        }

    //no? great, then cast the CP!
    }else{
        //case a Control Panel Controller
        $controller = adminFactory::cast('controlPanel',$db,$smarty,$myLog);
    }
    #
    ###### -- End Admin Module Registry -- ######

    ###### -- Actual Functionality -- ###########
    #
    //see if we can show what we are asked to show
    try{
        $controller->display(); // show whatever you have to show

    //what a pity, no joy!
    }catch(exception $e){

        //get hold of the error message
        $myLog->recordError($e->getMessage(),$e->getCode());

        //display an internal server error page
        //$smarty->display("500.html");
    }
    #
    ###### -- This is amazingly beautiful -- ####
